<template>
  <div class="layout-container">
    <y-header :show-nav="false" />
    <div class="w">
      <div class="content">
        <div class="account-sidebar">
          <div class="avatar gray-box ">
            <div>
              <img :src="userInfo.info.avatar">
              <h5>{{ userInfo.info.name }}</h5>
            </div>
            <div class="box-inner">
              <ul class="account-nav">
                <li
                  v-for="(item,i) in nav"
                  :key="i"
                  :class="{current:item.name===title}"
                  @click="tab(item)"
                >
                  <a href="javascript:;">{{ item.name }}</a></li>
              </ul>
            </div>
          </div>
        </div>
        <div class="account-content">
          <router-view :is-merchant="userInfo.info.isMerchant" />
        </div>
      </div>
    </div>
    <y-footer />

  </div>

</template>
<script>
import YFooter from '@/common/footer'
import YHeader from '@/common/header'
import { mapState } from 'vuex'
export default {
  components: {
    YFooter,
    YHeader
  },
  data() {
    return {
      title: '我的订单',
      nav: [
        { name: '我的订单', path: 'orderList' },
        { name: '账户资料', path: 'information' },
        { name: '收货地址', path: 'addressList' },
        { name: '我的优惠', path: 'coupon' },
        { name: '我的店铺', path: 'shop' }
      ],
      editAvatar: true
    }
  },
  computed: {
    ...mapState(['userInfo'])
  },
  watch: {
    $route(to) {
      const path = this.$route.path.split('/')[2]
      this.nav.forEach(item => {
        if (item.path.split('?')[0] === 'shop') {
          item.name = this.userInfo.info.isMerchant ? '我的商铺' : '申请成为商家'
        }
        if (item.path === path) {
          this.title = item.name
        }
      })
    }
  },
  created() {
    const path = this.$route.path.split('/')[2]
    this.nav.forEach(item => {
      if (item.path.split('?')[0] === 'shop') {
        item.name = this.userInfo.info.isMerchant ? '我的商铺' : '申请成为商家'
      }
      if (item.path === path) {
        this.title = item.name
      }
    })
  },
  methods: {
    tab(e) {
      this.$router.push({ path: '/user/' + e.path })
    }
  }
}
</script>
<style lang="scss" rel="stylesheet/scss" scoped>
  @import "../../assets/style/mixin";

  .w {
    padding-top: 40px;
  }

  .content {
    display: flex;
    height: 100%;
  }

  .account-sidebar {
    width: 210px;
    border-radius: 6px;
    .avatar {
      padding-top: 20px;
      border-radius: 10px;
      text-align: center;
      img {
        width: 168px;
        height: 168px;
      }
      h5 {
        font-size: 18px;
        line-height: 48px;
        font-weight: 700;
      }
    }
    .account-nav {
      padding-top: 15px;
      li {
        position: relative;
        height: 48px;
        border-top: 1px solid #EBEBEB;
        line-height: 48px;
        &:hover {
          a {
            position: relative;
            z-index: 1;
            height: 50px;
            background-color: #98AFEE;
            line-height: 50px;
            color: #FFF;
          }

        }
        a {
          display: block;
        }
        &.current {
          a {
            position: relative;
            z-index: 1;
            height: 50px;
            background-color: #98AFEE;
            line-height: 50px;
            color: #FFF;
          }
        }

      }
    }
  }

  .account-content {
    margin-left: 20px;
    flex: 1;
  }

</style>
